#include <cstdio>
#include <cstring>

int main( )
{
    int m1, m2, r1, r2, r3, i;
    char command[ 201 ];
    while ( scanf("%d%d", &m1, &m2) != EOF )
    {
        scanf("%s", command);
        r1 = r2 = r3 = 0;
        for ( i = 0; i < strlen( command ); i++ )
        {
            switch( command[ i ] )
            {
                case 'A': r1 = m1; break;
                case 'B': r2 = m2; break;
                case 'C': m1 = r3; break;
                case 'D': m2 = r3; break;
                case 'E': r3 = r1 + r2; break;
                case 'F': r3 = r1 - r2; break;
            }
        }
        printf("%d,%d\n", m1, m2);
    }
    return 0;
}
